package com.hkts.management.cargodetail.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.cargodetail.entity.HktsCargoDetail;
import com.hkts.management.cargodetail.mapper.HktsCargoDetailMapper;
import com.hkts.management.cargodetail.service.IHktsCargoDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.feign.FeignInterface;
import com.hkts.management.model.TO.HontUserTo;
import com.hkts.management.properties.HistoryProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2021-04-22
 */
@Service
@Transactional
public class HktsCargoDetailServiceImpl extends ServiceImpl<HktsCargoDetailMapper, HktsCargoDetail> implements IHktsCargoDetailService {


    @Autowired
    private HktsCargoDetailMapper hktsCargoDetailMapper;

    @Autowired
    private FeignInterface feignInterface;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public IPage<HktsCargoDetail> selectPage(Page<HktsCargoDetail> page, HktsCargoDetail hktsCargoDetail) {
        QueryWrapper<HktsCargoDetail> query = Wrappers.query();
        QueryWrapper<HktsCargoDetail> entityWrapper = getEntityWrapper(query, hktsCargoDetail);
        return hktsCargoDetailMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsCargoDetail> selectList(HktsCargoDetail hktsCargoDetail) {
        QueryWrapper<HktsCargoDetail> query = Wrappers.query();
        QueryWrapper<HktsCargoDetail> entityWrapper = getEntityWrapper(query, hktsCargoDetail);
        return hktsCargoDetailMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsCargoDetail> getEntityWrapper(QueryWrapper<HktsCargoDetail> entityWrapper, HktsCargoDetail hktsCargoDetail) {
        //条件拼接
        if (StringUtils.isNotBlank(hktsCargoDetail.getCargoId())) {
            entityWrapper.lambda().like(HktsCargoDetail::getCargoId, hktsCargoDetail.getCargoId());
        }
        return entityWrapper;
    }
    public HktsCargoDetail getHktsCargoDetailByCargoId(String cargoId){
        QueryWrapper<HktsCargoDetail> query = Wrappers.query();
        query.lambda().eq(HktsCargoDetail::getCargoId,cargoId);
        return hktsCargoDetailMapper.selectOne(query);
    }
}
